﻿Imports WiremetModel.Entities.SupplyOrders
Imports CrystalDecisions.CrystalReports.Engine

Public Class MiscellaneousOrderReportService
    Inherits OrderReportService


    Public Function GenerateReport(ByVal miscellaneousOrder As MiscellaneousOrder) As ReportDocument

        Dim miscellaneousOrderReport As New MiscellaneousOrderReport()

        Dim miscellaneousOrderReportData As New List(Of MiscellaneousOrderLineReportDataRow)
        For Each miscellaneousOrderLine As MiscellaneousOrderLine In miscellaneousOrder.OrderLines.OrderBy(Function(x) x.Product.Name).OrderBy(Function(x) x.Product.ProductType.Name)
            miscellaneousOrderReportData.Add(New MiscellaneousOrderLineReportDataRow With {
                                             .Id = miscellaneousOrderLine.Id,
                                             .MeasureUnit = miscellaneousOrderLine.MeasureUnit.Jednostka,
                                             .ProductName = miscellaneousOrderLine.Product.Name,
                                             .ProductType = miscellaneousOrderLine.Product.ProductType.Name,
                                             .Quantity = miscellaneousOrderLine.Quantity,
                                             .UnitPrice = miscellaneousOrderLine.UnitPrice
                               })
        Next

        miscellaneousOrderReport.SetDataSource(miscellaneousOrderReportData)
        SetParameterValues(MiscellaneousOrder, miscellaneousOrderReport)
        Return miscellaneousOrderReport

    End Function


End Class
